package com.sxz.sbs.module.client.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sxz.sbs.R;
import com.sxz.sbs.app.GlideApp;
import com.sxz.sbs.module.client.bean.StaffListBean;

import java.util.List;
/**
 *
 * @author hp
 * @date 2018/1/10
 * 分配到人员
 */

public class BuildingPersonAdapter extends BaseQuickAdapter<StaffListBean,BuildingPersonAdapter.ViewHolder> {

    private int defaultSelection = -1;

    public BuildingPersonAdapter(@Nullable List<StaffListBean> data) {
        super(R.layout.item_buildingperson,data);
    }


    @Override
    protected void convert(final BuildingPersonAdapter.ViewHolder helper, final StaffListBean item) {
        GlideApp.with(mContext).load(item.getUrl_HeadPhoto()).placeholder(R.drawable.ic_headportrait)
                .error(R.drawable.ic_headportrait).into((ImageView) helper.getView(R.id.iv_staff_head));
        helper.setText(R.id.title,item.getTxt_Name());
        helper.checkBox.setVisibility(View.VISIBLE);
        // 选中时设置单纯颜色
        if (helper.getAdapterPosition() == defaultSelection) {
            helper.checkBox.setChecked(true);
        } else {// 未选中时设置selector
            helper.checkBox.setChecked(false);
        }
    }

    class ViewHolder extends BaseViewHolder {
        CheckBox checkBox;
        public ViewHolder(View view) {
            super(view);
            checkBox =view.findViewById(R.id.checkBox1);
        }
    }
    public void setSelectPosition(int i) {
        this.defaultSelection = i;
    }
}